#ifndef NDB_H
#define NDB_H

#define SPLITER_REPLACE  "#&，"
#define  CSVSPLITER  ","


#include <QObject>

#include <QSqlDatabase>
#include <QString>
#include <QStringList>
#include <QSqlQuery>
#include <QDebug>
#include <QSqlError>
#include <QDateTime>
#include <QMessageBox>
#include <QFile>
#include <QApplication>
#include <QDir>
#include <QSet>
#include "note.h"
#include "taskitem.h"




typedef struct Field{
    QString _name;
    QString _type;
};



class Ndb : public QObject
{
    Q_OBJECT
public:
    explicit Ndb(QObject *parent = nullptr);
    explicit Ndb(QString dbName, QObject *parent = nullptr);

public:
    // 数据库
    static QSqlDatabase db;
    static QString tableName;
    static QSqlQuery query;

    static QString DateFormat;
    static QVector<Field> fields;

    // 数据库导出为csv
    static void DbOutputCsv(QString fileName);
    static bool DbInputCsv(QString fileName, const QString &columnName);


public:



    bool isTableExist(QString table);
    void createTaskTable(QString table);
    void createSubTaskTable();
    void createNoteTable();
    void createLogTable();
    void createTimevecTable();


    static int addTaskLog(int taskid, const QString taskname, int sort, unsigned int costtime,bool isfinished);
    static void addTimeVec(int taskid, int logid, QTime &start_time, QTime &end_time);
    static int addSubTasks(int taskid, QMap<int, subTask> &subTaskVec);
    static void deleteSubTask(int taskid, const QString subname);
    static void deleteSubTask(int subtaskid);
    static void updateSubTask(const subTask &subtask);


    static int getLastInsertId(const QString &tablename);

signals:
    void DataBaseOpenError();



};




#endif // NDB_H
